package cn.xxi.ai.application.dto;

import dev.langchain4j.model.chat.response.ChatResponse;
import dev.langchain4j.model.output.FinishReason;

public class Started extends StartedEvent<ChatResponse> {

    public Started() {
        super();
    }

    @Override
    public boolean persistent() {
        return false;
    }

    @Override
    public FinishedEvent toSuccessEvent(ChatResponse chatResponse) {
        return new Finished(
            chatResponse.tokenUsage().inputTokenCount(),
            chatResponse.tokenUsage().outputTokenCount(),
            chatResponse.finishReason(),
            Status.SUCCESS,
            null,
            startedAt
        );
    }

    @Override
    public FinishedEvent toFailureEvent(String error) {
        return new Finished(
            0, 0, FinishReason.OTHER,
            Status.FAILURE,
            error,
            startedAt
        );
    }
}
